define(function(require, exports){
	var pubjs = require('pubjs');
	var $ = require('jquery');
	var grid  = require('@base/highGrid');
	var util = require('util');

	var CreativeGrid = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'creative/list',
					param: {
						'IsDeleted': false
					},
					cols: [
						{name:'_id',text:"ID", sort: true},
						'CreativeNameWithThumb',
						{name:'Type',text:LANG("时长"), render: 'renderDuration'},
						{name:'Width',text:LANG("尺寸"), render: 'renderSize'}
					],
					subs: ['campaign', 'product', 'period', 'region', 'client', 'frequency'],
					tab: pubjs.config('metricsGroup/creative/tabs'),
					default_metrics : pubjs.config('metricsGroup/creative/metrics'),
					reqType: 'websocket',
					gridName: 'creative',
					hasSearch: false,
					hasFilter: false,
					subFilter: 'subFilter'
				}
			);
			this.Super('init', arguments);
		}
		,subFilter: function(subs, data){
			// 帐号行业类型：1 游戏，有产品版；2 电商，无产品版
			var user = pubjs.getUser();
			var trade = user.current.ExchangeInfo.CategoryId;

			util.each(subs, function(sub){
				// 有产品版的账号才有产品子表格
				if (sub.type === 'product') {
					sub.iconBtn.toggle(trade == 1);
				}
			});
		}
		,renderSize: function(i, val, data, con){
			return (data.Width && (data.Width + '*' + data.Height)) || LANG('未知')
		}
		,renderDuration: function(i, val, data, con){
			var div = $('<div/>');
			if(data && data.Video && data.Video.Duration){
				return div.text(+data.Video.Duration);
			}else{
				return div.text(0);
			}
		}
	});
	exports.base = CreativeGrid;

});